package org.sirmupadbapi.controller;

import org.sirmupadbapi.beans.Regimenvehicles;
import java.sql.Date; 
import java.io.Serializable;
import java.util.List;
import java.util.ArrayList;
import java.util.*;
import java.util.HashMap;
import java.util.Map;
import org.sirmupadbapi.persistencia.RegimenvehiclesPersistencia;
import org.sirmupadbapi.generales.Mensajeria;


/**
*
*  @author
*/

public class RegimenvehiclesController implements Serializable {
private static final long serialVersionUID = 1L;
private boolean withRelation= true;
public static Exception excepcion;



private List<Regimenvehicles> regimenvehicleslist;

private Regimenvehicles selectedregimenvehicles;



public boolean isWithRelation() {
    return withRelation;
}
public  void setWithRelation(boolean withRelation) {
    this.withRelation = withRelation;
}
public RegimenvehiclesController(){
}

public Regimenvehicles getSelectedRegimenvehicles() {
 return selectedregimenvehicles;
}

 public void setSelectedRegimenvehicles(Regimenvehicles selectedregimenvehicles) {
 this.selectedregimenvehicles = selectedregimenvehicles;
}


public List<Regimenvehicles> getRegimenvehicleslist() {
return regimenvehicleslist;
}

 public void setRegimenvehicleslist(List<Regimenvehicles> regimenvehicleslist) {
this.regimenvehicleslist = regimenvehicleslist;
}
/*
*  getMensaje()
*   devuelve el mensaje encontrado...
*/
public String getMensaje() {
   String lexcepcion = excepcion.toString();
   if (lexcepcion.indexOf(":") != -1) {
       lexcepcion = lexcepcion.substring(lexcepcion.indexOf(":") + 1);
   }
  return lexcepcion;
}


/**
*
* insert()
*/

public boolean insert (Regimenvehicles regimenvehicles) {
try{
java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/sirmupadbapi/properties/mensajes");
   if (validate(regimenvehicles)) {
     if (findByPrimaryKey(regimenvehicles)==null) {
         if (!RegimenvehiclesPersistencia.insert(regimenvehicles)) {
                 excepcion = RegimenvehiclesPersistencia.excepcion;
          }
          else{
             return true;
           }
       }else{
               excepcion=new Exception(bundle.getString("msg.recordexists"));
            return false;
       }
    }
  }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"insert()");
  }
  return false;
}


/**
*
* update()
*/

public boolean update (Regimenvehicles regimenvehicles) {
try{
java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/sirmupadbapi/properties/mensajes");
   if (validate(regimenvehicles)) {
 if (RegimenvehiclesPersistencia.exists(regimenvehicles)) {
     if (!RegimenvehiclesPersistencia.update(regimenvehicles)) {
                excepcion = RegimenvehiclesPersistencia.excepcion;
     }
     else{
            return true;
     }
   }else{
               excepcion=new Exception(bundle.getString("msg.nofoundprimarykey"));
            return false;
     }
  }
  }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"update()");
  }
  return false;
}


/**
*
* update(String sqlupdate)
*/

public boolean update(String sqlupdate) {
try{
     if (!RegimenvehiclesPersistencia.update(sqlupdate)) {
                excepcion = RegimenvehiclesPersistencia.excepcion;
     }
     else{
            return true;
     }
  }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"update()");
  }
  return false;
}


/**
*
* updatePrimaryKey()
*/

public boolean updatePrimaryKey (Regimenvehicles regimenvehicles_old , Regimenvehicles regimenvehicles) {
try{
java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/sirmupadbapi/properties/mensajes");
   if (validate(regimenvehicles_old)) {
 if (RegimenvehiclesPersistencia.exists(regimenvehicles_old)) {
     if (!RegimenvehiclesPersistencia.updatePrimaryKey(regimenvehicles_old,regimenvehicles)) {
                excepcion = RegimenvehiclesPersistencia.excepcion;
     }
     else{
            return true;
     }
   }else{
               excepcion=new Exception(bundle.getString("msg.nofoundprimarykey"));
            return false;
     }
  }
  }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"updatePrimaryKey()");
  }
  return false;
}


/**
*
* delete()
*/

public boolean delete (Regimenvehicles regimenvehicles) {
try{
java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/sirmupadbapi/properties/mensajes");
 if (findByPrimaryKey(regimenvehicles)!=null) {
     if (!RegimenvehiclesPersistencia.delete(regimenvehicles)) {
                excepcion = RegimenvehiclesPersistencia.excepcion;
     }else{
            return true;
           }
   }else{
            excepcion=new Exception(bundle.getString("msg.nofoundprimarykey"));
            return false;
     }
  }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"delete()");
  }
  return false;
}


/**
*
* delete(String sqldelete)
*/

public boolean delete(String sqldelete) {
try{
     if (!RegimenvehiclesPersistencia.delete(sqldelete)) {
                excepcion = RegimenvehiclesPersistencia.excepcion;
     }else{
            return true;
           }
  }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"delete()");
  }
  return false;
}


/**
*
* deleteAll()
*/

public boolean deleteAll() {
try{
     if (!RegimenvehiclesPersistencia.deleteAll()) {
                excepcion = RegimenvehiclesPersistencia.excepcion;
     }
     else{
            return true;
     }
  }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"deleteAll()");
  }
  return false;
}


/**
*
* exists()
*/



public boolean exists(Regimenvehicles regimenvehicles) {
try{
   return RegimenvehiclesPersistencia.exists(regimenvehicles);
  }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"Exists()");
  }
 return false;
}


/**
*
* findPrimaryKey()
*/



public Regimenvehicles findByPrimaryKey(Regimenvehicles regimenvehicles) {
try{
    this.selectedregimenvehicles = RegimenvehiclesPersistencia.findByPrimaryKey(regimenvehicles);
    return selectedregimenvehicles;
  }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"findByPrimaryKey()");
  }
 return null;
}


/**
*
* findByIDVEHICULO()
*/

public boolean findByIDVEHICULO(Regimenvehicles regimenvehicles) {
  try{
     if(regimenvehicleslist != null){
        regimenvehicleslist.removeAll(regimenvehicleslist);
     }
     regimenvehicleslist = RegimenvehiclesPersistencia.findByIDVEHICULO(regimenvehicles,withRelation) ;
     if (regimenvehicleslist== null) {
                excepcion = RegimenvehiclesPersistencia.excepcion;
       }
       else{
            return true;
            }
    }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"findByIDVEHICULO()");
  }
  return false;
  }


/**
*
* findByIDREGIMEN()
*/

public boolean findByIDREGIMEN(Regimenvehicles regimenvehicles) {
  try{
     if(regimenvehicleslist != null){
        regimenvehicleslist.removeAll(regimenvehicleslist);
     }
     regimenvehicleslist = RegimenvehiclesPersistencia.findByIDREGIMEN(regimenvehicles,withRelation) ;
     if (regimenvehicleslist== null) {
                excepcion = RegimenvehiclesPersistencia.excepcion;
       }
       else{
            return true;
            }
    }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"findByIDREGIMEN()");
  }
  return false;
  }


/**
*
* findByVALOR()
*/

public boolean findByVALOR(Regimenvehicles regimenvehicles) {
  try{
     if(regimenvehicleslist != null){
        regimenvehicleslist.removeAll(regimenvehicleslist);
     }
     regimenvehicleslist = RegimenvehiclesPersistencia.findByVALOR(regimenvehicles,withRelation) ;
     if (regimenvehicleslist== null) {
                excepcion = RegimenvehiclesPersistencia.excepcion;
       }
       else{
            return true;
            }
    }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"findByVALOR()");
  }
  return false;
  }


/**
*
* findByPERIODOPAGO()
*/

public boolean findByPERIODOPAGO(Regimenvehicles regimenvehicles) {
  try{
     if(regimenvehicleslist != null){
        regimenvehicleslist.removeAll(regimenvehicleslist);
     }
     regimenvehicleslist = RegimenvehiclesPersistencia.findByPERIODOPAGO(regimenvehicles,withRelation) ;
     if (regimenvehicleslist== null) {
                excepcion = RegimenvehiclesPersistencia.excepcion;
       }
       else{
            return true;
            }
    }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"findByPERIODOPAGO()");
  }
  return false;
  }


/**
*
* findByMESPAGO()
*/

public boolean findByMESPAGO(Regimenvehicles regimenvehicles) {
  try{
     if(regimenvehicleslist != null){
        regimenvehicleslist.removeAll(regimenvehicleslist);
     }
     regimenvehicleslist = RegimenvehiclesPersistencia.findByMESPAGO(regimenvehicles,withRelation) ;
     if (regimenvehicleslist== null) {
                excepcion = RegimenvehiclesPersistencia.excepcion;
       }
       else{
            return true;
            }
    }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"findByMESPAGO()");
  }
  return false;
  }


/**
*
* findByFECHAINSCRIPCION()
*/

public boolean findByFECHAINSCRIPCION(Regimenvehicles regimenvehicles) {
  try{
     if(regimenvehicleslist != null){
        regimenvehicleslist.removeAll(regimenvehicleslist);
     }
     regimenvehicleslist = RegimenvehiclesPersistencia.findByFECHAINSCRIPCION(regimenvehicles,withRelation) ;
     if (regimenvehicleslist== null) {
                excepcion = RegimenvehiclesPersistencia.excepcion;
       }
       else{
            return true;
            }
    }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"findByFECHAINSCRIPCION()");
  }
  return false;
  }


/**
*
* findByIDUSUARIO()
*/

public boolean findByIDUSUARIO(Regimenvehicles regimenvehicles) {
  try{
     if(regimenvehicleslist != null){
        regimenvehicleslist.removeAll(regimenvehicleslist);
     }
     regimenvehicleslist = RegimenvehiclesPersistencia.findByIDUSUARIO(regimenvehicles,withRelation) ;
     if (regimenvehicleslist== null) {
                excepcion = RegimenvehiclesPersistencia.excepcion;
       }
       else{
            return true;
            }
    }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"findByIDUSUARIO()");
  }
  return false;
  }


/**
*
* findByFECHA()
*/

public boolean findByFECHA(Regimenvehicles regimenvehicles) {
  try{
     if(regimenvehicleslist != null){
        regimenvehicleslist.removeAll(regimenvehicleslist);
     }
     regimenvehicleslist = RegimenvehiclesPersistencia.findByFECHA(regimenvehicles,withRelation) ;
     if (regimenvehicleslist== null) {
                excepcion = RegimenvehiclesPersistencia.excepcion;
       }
       else{
            return true;
            }
    }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"findByFECHA()");
  }
  return false;
  }


/**
*
* findByACTIVO()
*/

public boolean findByACTIVO(Regimenvehicles regimenvehicles) {
  try{
     if(regimenvehicleslist != null){
        regimenvehicleslist.removeAll(regimenvehicleslist);
     }
     regimenvehicleslist = RegimenvehiclesPersistencia.findByACTIVO(regimenvehicles,withRelation) ;
     if (regimenvehicleslist== null) {
                excepcion = RegimenvehiclesPersistencia.excepcion;
       }
       else{
            return true;
            }
    }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"findByACTIVO()");
  }
  return false;
  }


/**
*
* findByIDMUNICIPIO()
*/

public boolean findByIDMUNICIPIO(Regimenvehicles regimenvehicles) {
  try{
     if(regimenvehicleslist != null){
        regimenvehicleslist.removeAll(regimenvehicleslist);
     }
     regimenvehicleslist = RegimenvehiclesPersistencia.findByIDMUNICIPIO(regimenvehicles,withRelation) ;
     if (regimenvehicleslist== null) {
                excepcion = RegimenvehiclesPersistencia.excepcion;
       }
       else{
            return true;
            }
    }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"findByIDMUNICIPIO()");
  }
  return false;
  }


/**
*
* locateByParameters()
*/

public boolean locateByParameters(Map parametros) {
  try{
     if(regimenvehicleslist != null){
        regimenvehicleslist.removeAll(regimenvehicleslist);
     }
     regimenvehicleslist = RegimenvehiclesPersistencia.locateByParameters(parametros,withRelation);
     if (regimenvehicleslist== null) {
                excepcion = RegimenvehiclesPersistencia.excepcion;
       }
       else{
            return true;
            }
    }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"locateByParameters()");
  }
  return false;
}


/**
*
* Func(String funcion, String campo)
*/

public Double func(String funcion, String campo) {
  try{
     return RegimenvehiclesPersistencia.func(funcion,campo);
    }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"func()");
  }
  return 0.0;
}


/**
*
* Double func(String funcion, String campo, String where)
*/

public Double func(String funcion, String campo,String where) {
  try{
     return RegimenvehiclesPersistencia.func(funcion,campo,where);
    }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"Func()");
  }
  return 0.0;
}


/**
*
* count()
*/

public Integer count() {
  try{
     int x =RegimenvehiclesPersistencia.count();
    return x;
    }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"count()");
  }
 return 0;
}


/**
*
* count(String sql)
*/

public Integer count(String sqlquery) {
  try{
     int x =RegimenvehiclesPersistencia.count(sqlquery);
    return x;
    }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"count()");
  }
 return 0;
}


/**
*
* query()
*/

public boolean query(String query) {
  try{
     if(regimenvehicleslist != null){
        regimenvehicleslist.removeAll(regimenvehicleslist);
     }
     regimenvehicleslist = RegimenvehiclesPersistencia.query(query,withRelation);
     if (regimenvehicleslist== null) {
                excepcion = RegimenvehiclesPersistencia.excepcion;
       }
       else{
            return true;
            }
    }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"query()");
  }
  return false;
}


/**
*
* selectAll()
*/



public boolean selectAll() {
  try{
     if(regimenvehicleslist != null){
        regimenvehicleslist.removeAll(regimenvehicleslist);
     }
     Map<String, String> parametros = new HashMap<String, String>();
     regimenvehicleslist = RegimenvehiclesPersistencia.getListRecords(parametros,withRelation);
     if (regimenvehicleslist== null) {
                excepcion = RegimenvehiclesPersistencia.excepcion;
       }
       else{
            return true;
            }
    }catch(Exception ex){
     Mensajeria.MensajeError( ex ,"SelectAll()");
  }
            return false;
}


public boolean validate(Regimenvehicles regimenvehicles) {
 try{
java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/sirmupadbapi/properties/mensajes");

if (regimenvehicles.getIDVEHICULO() == null || regimenvehicles.getIDVEHICULO().equals("")){
   excepcion=new Exception(bundle.getString("IDVEHICULO")  + "  " + bundle.getString("msg.nonulo"));
  return false;
}
if (regimenvehicles.getIDREGIMEN() == null || regimenvehicles.getIDREGIMEN().equals("")){
   excepcion=new Exception(bundle.getString("IDREGIMEN")  + "  " + bundle.getString("msg.nonulo"));
  return false;
}
if (regimenvehicles.getACTIVO() == null || regimenvehicles.getACTIVO().equals("")){
   excepcion=new Exception(bundle.getString("ACTIVO")  + "  " + bundle.getString("msg.nonulo"));
  return false;
}
if (regimenvehicles.getIDMUNICIPIO() == null || regimenvehicles.getIDMUNICIPIO().equals("")){
   excepcion=new Exception(bundle.getString("IDMUNICIPIO")  + "  " + bundle.getString("msg.nonulo"));
  return false;
}
  return true;
 }catch(Exception ex){
   Mensajeria.MensajeError(ex, "validate()");
  return false;

  }
}


}
